#pragma once
#pragma warning(disable:4996)       // disable checked iterator errors http://msdn.microsoft.com/en-us/library/aa985965(VS.80).aspx 

//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101

#include <Macros.h>
#include <CoVector.h>
#include <CoMatrix.h>
#include <CoCube.h>
#include <ValueHelpers.h>
#include <Settings.h>

#include <gen/QL/Termstructures/YieldTermStructure.h>
#pragma unmanaged 
#include <ql\termstructures\yield\flatforward.hpp>
#include <boost/smart_ptr/detail/spinlock.hpp>
#pragma managed 

using namespace System;
using namespace QuantLib;
using namespace Cephei;

using namespace Cephei::QL::Times;
using namespace Cephei::QL;
using namespace Cephei::QL::Termstructures;
#define HANDLE
#undef ABSTRACT
#undef STRUCT
namespace Cephei { namespace QL { namespace Termstructures { namespace Yield {
	//////////////////////////////////////////////////////////////////////////////////////////////
	// implementation of IFlatForward
	public ref class CFlatForward : 
            public CYieldTermStructure,
            public Cephei::QL::Termstructures::Yield::IFlatForward
	{
	protected: 
		boost::shared_ptr<QuantLib::FlatForward>* _ppFlatForward;
#ifdef HANDLE
		QuantLib::Handle<QuantLib::FlatForward>* _phFlatForward;
#endif
		Object^ _FlatForwardOwner;     // reference to object that manages the storage for this object
	internal:
		CFlatForward (UInt32 settlementDays, Cephei::QL::Times::ICalendar^ calendar, Double forward, Cephei::QL::Times::IDayCounter^ dayCounter, Microsoft::FSharp::Core::FSharpOption<QL::CompoundingEnum>^ compounding, Microsoft::FSharp::Core::FSharpOption<QL::Times::FrequencyEnum>^ frequency);
		CFlatForward (UInt32 settlementDays, Cephei::QL::Times::ICalendar^ calendar, Cephei::QL::IQuote^ forward, Cephei::QL::Times::IDayCounter^ dayCounter, Microsoft::FSharp::Core::FSharpOption<QL::CompoundingEnum>^ compounding, Microsoft::FSharp::Core::FSharpOption<QL::Times::FrequencyEnum>^ frequency);
		CFlatForward (DateTime referenceDate, Double forward, Cephei::QL::Times::IDayCounter^ dayCounter, Microsoft::FSharp::Core::FSharpOption<QL::CompoundingEnum>^ compounding, Microsoft::FSharp::Core::FSharpOption<QL::Times::FrequencyEnum>^ frequency);
		CFlatForward (DateTime referenceDate, Cephei::QL::IQuote^ forward, Cephei::QL::Times::IDayCounter^ dayCounter, Microsoft::FSharp::Core::FSharpOption<QL::CompoundingEnum>^ compounding, Microsoft::FSharp::Core::FSharpOption<QL::Times::FrequencyEnum>^ frequency);
        CFlatForward (boost::shared_ptr<QuantLib::FlatForward>& childNative, Object^ owner);
        CFlatForward (QuantLib::FlatForward& childNative, Object^ owner);
        CFlatForward (CFlatForward^ copy);
        CFlatForward (System::Type^ t);
#ifdef STRUCT
        CFlatForward (QuantLib::FlatForward childNative);
#endif       
#ifdef HANDLE
		CFlatForward (QuantLib::Handle<QuantLib::FlatForward>& childNative, Object^ owner);
		CFlatForward (QuantLib::Handle<QuantLib::FlatForward> childNative);
#endif
		virtual ~CFlatForward ();
		!CFlatForward ();

	internal:
		QuantLib::FlatForward& GetReference ();
		boost::shared_ptr<QuantLib::FlatForward>& GetShared ();
		QuantLib::FlatForward* GetPointer ();
        void SetFlatForward (boost::shared_ptr<QuantLib::FlatForward> native)
        {
            if (_ppFlatForward != NULL)
                delete _ppFlatForward;
            _ppFlatForward = new boost::shared_ptr<QuantLib::FlatForward> (native);
            SetYieldTermStructure (boost::dynamic_pointer_cast<QuantLib::YieldTermStructure> (*_ppFlatForward));
        }
#ifdef HANDLE
		QuantLib::Handle<QuantLib::FlatForward>& GetHandle ();
#endif
		virtual bool HasNative () override;
    public:
        property QL::CompoundingEnum Compounding 
        {
		    virtual QL::CompoundingEnum get () ;
        }
        property QL::Times::FrequencyEnum CompoundingFrequency 
        {
		    virtual QL::Times::FrequencyEnum get () ;
        }
        property DateTime MaxDate 
        {
		    virtual DateTime get () ;
        }
        property Cephei::QL::Termstructures::Yield::IFlatForward^ Update 
        {
		    virtual Cephei::QL::Termstructures::Yield::IFlatForward^ get () ;
        }
        property DateTime M2009_MaxDate 
        {
            virtual DateTime get () = Cephei::QL::ITermStructure::MaxDate::get
            {
                return ((Cephei::QL::Termstructures::Yield::IFlatForward^)this)->MaxDate;
            }
        }
        property Cephei::QL::ITermStructure^ M2009_Update 
        {
            virtual Cephei::QL::ITermStructure^ get () = Cephei::QL::ITermStructure::Update::get
            {
                return ((Cephei::QL::Termstructures::Yield::IFlatForward^)this)->Update;
            }
        }
    };
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// Factory class
	public ref class CFlatForward_Factory : public System::MarshalByRefObject,  public IFlatForward_Factory
	{
	public:
        virtual IFlatForward^ Create (UInt32 settlementDays, Cephei::QL::Times::ICalendar^ calendar, Double forward, Cephei::QL::Times::IDayCounter^ dayCounter, Microsoft::FSharp::Core::FSharpOption<QL::CompoundingEnum>^ compounding, Microsoft::FSharp::Core::FSharpOption<QL::Times::FrequencyEnum>^ frequency);
        virtual IFlatForward^ Create (UInt32 settlementDays, Cephei::QL::Times::ICalendar^ calendar, Cephei::QL::IQuote^ forward, Cephei::QL::Times::IDayCounter^ dayCounter, Microsoft::FSharp::Core::FSharpOption<QL::CompoundingEnum>^ compounding, Microsoft::FSharp::Core::FSharpOption<QL::Times::FrequencyEnum>^ frequency);
        virtual IFlatForward^ Create (DateTime referenceDate, Double forward, Cephei::QL::Times::IDayCounter^ dayCounter, Microsoft::FSharp::Core::FSharpOption<QL::CompoundingEnum>^ compounding, Microsoft::FSharp::Core::FSharpOption<QL::Times::FrequencyEnum>^ frequency);
        virtual IFlatForward^ Create (DateTime referenceDate, Cephei::QL::IQuote^ forward, Cephei::QL::Times::IDayCounter^ dayCounter, Microsoft::FSharp::Core::FSharpOption<QL::CompoundingEnum>^ compounding, Microsoft::FSharp::Core::FSharpOption<QL::Times::FrequencyEnum>^ frequency);
    };
   
/*Cephei*/ } /*QL*/ } /*Termstructures*/ } /*Yield */}
